package com.car.loan.project.tool.controller;

import com.car.loan.framework.aspectj.lang.annotation.Log;
import com.car.loan.framework.aspectj.lang.enums.BusinessType;
import com.car.loan.framework.web.domain.AjaxResult;
import com.car.loan.project.tool.util.AliOcrUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import java.io.File;
import java.io.IOException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

/**
 * @author huangding
 * @description
 * @date 2019/10/23 23:06
 */
@RestController
@RequestMapping("/tool/ocr")
@Api(value = "ocr接口", tags = "工具接口-ocr识别")
public class OcrController {

    @Autowired
    private AliOcrUtil aliOcrUtil;

    @PostMapping("idCard")
    @ApiOperation("身份证识别")
    @Log(title = "身份证识别", businessType = BusinessType.OCR)
    public AjaxResult idCard(@RequestParam("file") MultipartFile files,
        @ApiParam(value = "正反面类型face/back", defaultValue = "face", required = true) String type)
        throws IOException {
        return aliOcrUtil.ocrIdCard(type, files.getBytes());
    }

    @PostMapping("divingCard")
    @ApiOperation("行驶证识别")
    @Log(title = "行驶证识别", businessType = BusinessType.OCR)
    public AjaxResult divingCard(@RequestParam("file") MultipartFile files,
        @ApiParam(value = "正反面类型face/back", defaultValue = "face", required = true) String type)
        throws IOException {
        return aliOcrUtil.ocrDivingCard(type, files.getBytes());
    }

}
